package com.uniledger.commonlib.pinkeyboard;

import android.text.TextUtils;
import java.util.ArrayList;
import java.util.List;

public class PayThirdDesc {

    public String label;
    public String desc;

    private PayThirdDesc(String label, String desc) {
        this.label = label;
        this.desc = desc;
    }

    /**
     * 返回数据列表
     *
     * @param result
     * @return
     */
    public static List<PayThirdDesc> payDescList(PayThirdResult result) {
            return createTransferList(result);
    }

    /**
     * 转账成功
     *
     * @return
     */
    private static List<PayThirdDesc> createTransferList(PayThirdResult info) {
        List<PayThirdDesc> list = new ArrayList<>();
        list.add(new PayThirdDesc("To", info.receiver));
        list.add(new PayThirdDesc("Fee Deducted", info.getFee()));
        list.add(new PayThirdDesc("Hash",info.getHashStr()));
        return list;
    }

    /**
     * 充值成功
     *
     * @return
     */
    private static List<PayThirdDesc> createChargeList(PayThirdResult info) {
        List<PayThirdDesc> list = new ArrayList<>();
        list.add(new PayThirdDesc("Wallet Balance", info.balance + info.currencyCode));
        list.add(new PayThirdDesc("Bank Card", getSubCardNo(info)));
        list.add(new PayThirdDesc("Remark", info.remark));
        list.add(new PayThirdDesc("Hash",info.getHashStr()));
        return list;
    }

    private static String getSubCardNo(PayThirdResult result) {
        String numStr = result.cardNo;
        if (!TextUtils.isEmpty(numStr) && numStr.length() > 4) {
            return result.bankCard + "****" + numStr.substring(numStr.length() - 4, numStr.length());
        } else {
            return result.bankCard + "****" + numStr;
        }
    }

    /**
     * 提现成功
     *
     * @return
     */
    private static List<PayThirdDesc> createWithdrawList(PayThirdResult info) {
        List<PayThirdDesc> list = new ArrayList<>();
        list.add(new PayThirdDesc("To Bank Card", getSubCardNo(info)));
        list.add(new PayThirdDesc("Withdraw Amount", info.amount + info.currencyCode));
        list.add(new PayThirdDesc("Arrival Amount", info.arriveAmount + info.arriveCurrency));
        list.add(new PayThirdDesc("Fee Deducted", info.getFee()));
        list.add(new PayThirdDesc("Exchange Rate", getRateStr(info)));
        list.add(new PayThirdDesc("Hash",info.getHashStr()));
        return list;
    }

    private static String getRateStr(PayThirdResult info) {
        String string = "1 %1$s = %2$s %3$s";
        return String.format(string, info.currencyCode, info.rate, info.arriveCurrency);
    }
}
